#!/bin/bash


#data_date=$1
add_sql="insert overwrite table jtp_oms_dwd.dwd_oms_order_item_incr partition (dt = '${data_date}')
         select t1.id,
                t1.order_id,
                t1.order_sn,
                t2.member_id,
                t1.product_id,
                t1.product_name,
                t1.product_brand,
                t1.product_price,
                t1.product_quantity,
                t1.product_sku_id,
                t1.product_category_id,
                t1.promotion_amount,
                t1.coupon_amount,
                t1.integration_amount,
                t1.real_amount,
                t1.gift_integration,
                t1.gift_growth,
                t1.create_time,
                t1.modify_time
         from (select id,
                      order_id,
                      order_sn,
                      product_id,
                      product_pic,
                      product_name,
                      product_brand,
                      product_sn,
                      product_price,
                      product_quantity,
                      product_sku_id,
                      product_sku_code,
                      product_category_id,
                      sp1,
                      sp2,
                      sp3,
                      promotion_name,
                      promotion_amount,
                      coupon_amount,
                      integration_amount,
                      real_amount,
                      gift_integration,
                      gift_growth,
                      product_attr,
                      create_time,
                      modify_time
               from jtp_oms_ods.ods_oms_order_item_incr
               where dt = '${data_date}') t1
                  join (select id,
                               member_id
                        from jtp_oms_ods.ods_oms_order_incr
                        where dt = '${data_date}'
                        and date_format(create_time,  'yyyy-MM-dd') = '${data_date}'
                        ) t2 on t1.order_id = t2.id;
"

/opt/module/spark/bin/beeline -u jdbc:hive2://node101:10001 -n bwie -e "${add_sql}"